<?php

include __DIR__.'/function.php';


$url = 'https://news.ke.com/bj/baike/0033/';

$html = http_request($url);
// echo $html;

//1.使用正则匹配 title

//$preg = '/<title>(.*)<\/title>/'; 

//$preg = '/<div>(.*)<\/div>/iUs'; //i忽略大小写  U禁止贪婪 s忽略换行
// $preg = '#<div>(.*)</div>#iUs'; //i忽略大小写  U禁止贪婪 s忽略换行

// preg_match_all($preg,$html,$arr);



//2---------------
$dom = new DOMDocument();
  //忽略html不严格的格式
libxml_use_internal_errors(1);
$dom->loadHTML($html);
//转为xpath对象
$xpath = new DOMXPath($dom);


//查询路径
// $query = '/html/head/title';

// $nodeList = $xpath->query($query);

// foreach($nodeList as $item){
//     echo $item->nodeValue;
// }


//查询所有的图片
// $query = '//img/@data-original';
$query = '//img/@data-original';

// /html/body/div[3]/div[2]/div/div[2]/div[2]/div[1]/a/img  


$nodeList = $xpath->query($query);

foreach($nodeList as $item){
    echo $item->nodeValue;
}




